const express = require('express')

const app = express()

app.listen(3000, () => {
    console.log('服务已开启。。。')
})

//声明路由中间件
const checkCodeMiddleware = (req,res,next) => {
    if(req.query.code === '521'){
        next()
    }else{
        res.send('暗号错误')
    }
}

app.get('/home', checkCodeMiddleware,(req, res) => {
    res.send('前台首页')
})

app.get('/admin', checkCodeMiddleware,(req, res) => {
    res.send('后台首页')
})

app.all('*', (req, res) => {
    res.status(404)
    res.send('404 Not Found')
})